package com.erdos.upc.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.erdos.common.dao.IBatisGenericDaoImpl;
import com.erdos.upc.dao.RoleDao;
import com.erdos.upc.entity.Role;


public class RoleDaoImpl extends IBatisGenericDaoImpl<Role> implements RoleDao {

    /* (non-Javadoc)
	 * @see com.hp.upc.dao.RoleDao#deleteRolePrivilege(java.lang.Long, java.lang.Long)
	 * @param roleSid
	 * @param privilegeSid
	 */
	public void deleteRolePrivilege(Long roleSid) {
		this.getSqlMapClientTemplate().delete("Role.deleteRolePrivilege",roleSid);
		
	}

	/* (non-Javadoc)
	 * @see com.hp.upc.dao.RoleDao#deleteRoleUserGroup(java.lang.Long, java.lang.Long)
	 * @param roleSid
	 * @param userGroupSid
	 */
	public void deleteRoleUserGroup(Long roleSid) {
		this.getSqlMapClientTemplate().delete("Role.deleteRoleUserGroup", roleSid);		
	}

	/* (non-Javadoc)
	 * @see com.hp.upc.dao.RoleDao#insertRolePrivilege(java.lang.Long, java.lang.Long)
	 * @param roleSid
	 * @param privilegeSid
	 */
	public void insertRolePrivilege(Role role, Long privilegeSid) {
		Map<String, Object> conditions = new HashMap<String, Object>();
		conditions.put("roleSid", role.getSid());
		conditions.put("privilegeSid",privilegeSid);
		conditions.put("createdBy", role.getCreatedBy());
		conditions.put("createdDt", role.getCreatedDt());
		conditions.put("version", role.getVersion());
		conditions.put("updatedBy", role.getUpdatedBy());
		conditions.put("updatedDt",role.getUpdatedDt());
		this.getSqlMapClientTemplate().insert("Role.insertRolePrivilege", conditions);

		
	}
	
	/*(non-Javadoc)
	 * @see com.hp.upc.dao.RoleDao#findByPrivilegeCode(java.lang.String)
	 * @param privilegeCode
	 */
	@SuppressWarnings("unchecked")
    public List<Role> findByPrivilegeCode(String privilegeCode) {
        return getSqlMapClientTemplate().queryForList("Role.findByPrivilegeCode", privilegeCode);
    }
}
